#!/bin/bash

# show the tips
echo "=========================================="
echo "Welcome to use swg command tool"
echo "This is the arguments of this tool:"
echo "1. name or -n=[name]: the folder name (the name of the target project)"
echo "2. dir or -d=[dir]: the folder to write to (start with ./)"
echo "3. writer or -w=[writer]: the name of the writer (default is ts+axios)"
echo "4. offline or -o=[isOffLine]: use local file (use the file of this project's sources folder)"
echo "5. user or -u=[user]: the swagger.json file's visitor name of BasicAuthToken (ignored with offline)"
echo "6. pass or -p=[pass]: the swagger.json file's visitor password of BasicAuthToken (ignored with offline)"
echo "7. addr or -a=[addr]: the path of the swagger.json file (net url with online, relative path with offline)"
echo "=========================================="
echo "The writers: js+axios, js+fetch, ts+axios, ts+fetch, flutter+dio"
echo "=========================================="
echo "Example: swg -n=\"test\" -d=\"./api\" -w=\"ts+axios\" -u=\"swagger\" -p=\"123456\" -a=\"http://localhost/swagger/v1\""
echo "=========================================="

# 循环获取用户输入
while true; do
    # get the command
    read -p "Please enter your command: " cmdStr

    # get the cmd name and parms
    cmdName=$(echo "$cmdStr" | awk '{print $1}')
    cmdArgs=$(echo "$cmdStr" | cut -d' ' -f2-)

    # check cmd name is swg
    if [[ "$cmdName" == "swg" ]]; then
        # excute the cmd with parms
        node ./lib/index.js $cmdArgs
    else
        # cmd name is not swg
        echo "The command \"$cmdName\" does not exist. Please try again."
    fi
done